package com.sxhuayuan.parking.controller.agent;

import com.sxhuayuan.parking.compenent.Page;
import com.sxhuayuan.parking.compenent.Pageable;
import com.sxhuayuan.parking.compenent.web.RespMessage;
import com.sxhuayuan.parking.controller.BaseController;
import com.sxhuayuan.parking.entity.Agent;
import com.sxhuayuan.parking.entity.ProfitStatistics;
import com.sxhuayuan.parking.service.AgentService;
import com.sxhuayuan.parking.service.ProfitStatisticsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author 何龙
 * @create 2019-04-27 17:34
 */
@RestController(value = "agentProfitStatisticsController")
@RequestMapping("/agent/profitstatistics")
public class ProfitStatisticsController extends BaseController {
	@Resource(name = "profitStatisticsServiceImpl")
	ProfitStatisticsService service;
	@Resource(name = "agentServiceImpl")
	AgentService agentService;

	@PostMapping("/list")
	public RespMessage list(@RequestBody Pageable pageable) {
		Agent agent = agentService.getCurrent();
		if (agent == null) {
			return invalidToken();
		}
		Page<ProfitStatistics> page = service.findPage(pageable, agent);
		return successResp(page);
	}

	/**
	 * 根据查询条件统计分润
	 * 
	 * @param pageable
	 *            分页查询条件
	 * @return 总分润 微信分润 支付宝分润
	 */
	@PostMapping("/sum/money")
	public RespMessage sumMoney(@RequestBody Pageable pageable) {
		Agent agent = agentService.getCurrent();
		BigDecimal[] bigDecimals = service.sumByPage(pageable, agent);
		return successResp(bigDecimals);
	}
}
